import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { TechnicianSkillApi } from '#/api/spa/technicians/skill';

import { DICT_SPA_TYPE } from '#/utils/dictSpa';
import { z } from '#/adapter/form';
import { DICT_TYPE, getDictOptions, getRangePickerDefaultProps } from '#/utils';

/** 新增/修改的表单 */
export function useFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'id',
      component: 'Input',
      dependencies: {
        triggerFields: [''],
        show: () => false,
      },
    },
    {
      fieldName: 'technicianId',
      label: '技师ID',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入技师ID',
      },
    },
    {
      fieldName: 'skillName',
      label: '技能名称',
      rules: 'required',
      component: 'Input',
      componentProps: {
        placeholder: '请输入技能名称',
      },
    },
    {
      fieldName: 'skillLevel',
      label: '技能等级',
      component: 'Input',
      componentProps: {
        placeholder: '请输入技能等级',
      },
    },
    {
      fieldName: 'skillScore',
      label: '技能评分',
      component: 'Input',
      componentProps: {
        placeholder: '请输入技能评分',
      },
    },
    {
      fieldName: 'certificationDate',
      label: '认证日期',
      component: 'DatePicker',
      componentProps: {
        showTime: true,
        format: 'YYYY-MM-DD HH:mm:ss',
        valueFormat: 'x',
      },
    },
    {
      fieldName: 'validityPeriod',
      label: '有效期(天)',
      component: 'Input',
      componentProps: {
        placeholder: '请输入有效期(天)',
      },
    },
    {
      fieldName: 'skillDescription',
      label: '技能描述',
      component: 'RichTextarea',
    },
    {
      fieldName: 'scope',
      label: '权限范围',
      component: 'Input',
      componentProps: {
        placeholder: '请输入权限范围',
      },
    },
    {
      fieldName: 'scoperef',
      label: '权限引用',
      component: 'Input',
      componentProps: {
        placeholder: '请输入权限引用',
      },
    },
  ];
}

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'technicianId',
      label: '技师ID',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入技师ID',
      },
    },
    {
      fieldName: 'skillName',
      label: '技能名称',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入技能名称',
      },
    },
    {
      fieldName: 'skillLevel',
      label: '技能等级',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入技能等级',
      },
    },
    {
      fieldName: 'skillScore',
      label: '技能评分',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入技能评分',
      },
    },
    {
      fieldName: 'certificationDate',
      label: '认证日期',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
    {
      fieldName: 'validityPeriod',
      label: '有效期(天)',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入有效期(天)',
      },
    },
    {
      fieldName: 'skillDescription',
      label: '技能描述',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入技能描述',
      },
    },
    {
      fieldName: 'scope',
      label: '权限范围',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入权限范围',
      },
    },
    {
      fieldName: 'scoperef',
      label: '权限引用',
      component: 'Input',
      componentProps: {
        allowClear: true,
        placeholder: '请输入权限引用',
      },
    },
    {
      fieldName: 'createTime',
      label: '创建时间',
      component: 'RangePicker',
      componentProps: {
        ...getRangePickerDefaultProps(),
        allowClear: true,
      },
    },
  ];
}

/** 列表的字段 */
export function useGridColumns(): VxeTableGridOptions<TechnicianSkillApi.TechnicianSkill>['columns'] {
  return [
    {
      field: 'id',
      title: '主键ID',
      minWidth: 120,
    },
    {
      field: 'technicianId',
      title: '技师ID',
      minWidth: 120,
    },
    {
      field: 'skillName',
      title: '技能名称',
      minWidth: 120,
    },
    {
      field: 'skillLevel',
      title: '技能等级',
      minWidth: 120,
    },
    {
      field: 'skillScore',
      title: '技能评分',
      minWidth: 120,
    },
    {
      field: 'certificationDate',
      title: '认证日期',
      minWidth: 120,
    },
    {
      field: 'validityPeriod',
      title: '有效期(天)',
      minWidth: 120,
    },
    {
      field: 'skillDescription',
      title: '技能描述',
      minWidth: 120,
    },
    {
      field: 'scope',
      title: '权限范围',
      minWidth: 120,
    },
    {
      field: 'scoperef',
      title: '权限引用',
      minWidth: 120,
    },
    {
      field: 'createTime',
      title: '创建时间',
      minWidth: 120,
      formatter: 'formatDateTime',
    },
    {
      title: '操作',
      width: 200,
      fixed: 'right',
      slots: { default: 'actions' },
    },
  ];
}
